import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';

// 列表数据
export const columns: BasicColumn[] = [
  {
    title: '任务类型',
    align: 'center',
    dataIndex: 'taskType_dictText',
  },
  {
    title: '设备任务',
    align: 'center',
    dataIndex: 'business_dictText',
  },
  {
    title: '油站名称',
    align: 'center',
    dataIndex: 'station',
    width: 350,
  },
  {
    title: '油站地址',
    align: 'center',
    dataIndex: 'device',
    customRender: ({ record }) => {
      return record.device.address;
    },
    width: 450,
  },
  {
    title: '设备名称',
    align: 'center',
    dataIndex: 'device',
    customRender: ({ record }) => {
      return record.device.name;
    },
  },
  {
    title: '设备厂商',
    align: 'center',
    dataIndex: 'device',
    customRender: ({ record }) => {
      return record.device.madeInCompany;
    },
    width: 300,
  },
  {
    title: '设备id',
    align: 'center',
    dataIndex: 'device',
    customRender: ({ record }) => {
      return record.device.code;
    },
  },
  {
    title: '设备ecqsId',
    align: 'center',
    dataIndex: 'device',
    customRender: ({ record }) => {
      return record.device.ecqsId;
    },
  },

  {
    title: '铅封ID',
    align: 'center',
    dataIndex: 'sealIds',
    width: 300,
    customRender: ({ text, record }) => {
      // 检查 sealIds 是否存在且为数组
      if (Array.isArray(record.sealIds) && record.sealIds.length > 0) {
        // 使用 join 方法将数组元素连接成字符串
        return record.sealIds.join(', ');
      } else {
        // 如果 sealIds 为空或不是数组，则返回空字符串或其他提示信息
        return '无';
      }
    },
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status_dictText',
  },
  {
    title: '操作员',
    align: 'center',
    dataIndex: 'createBy_dictText',
  },
  {
    title: '添加日期',
    align: 'center',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '备注',
    align: 'center',
    dataIndex: 'note',
  },
];
// 查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '任务类型',
    field: 'taskType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'task_type',
      placeholder: '任务类型',
      stringToNumber: true,
    },
  },
  {
    label: '任务状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'task_status',
      placeholder: '请选择任务状态',
      stringToNumber: true,
    },
  },
  {
    label: '使用单位',
    field: 'station',
    component: 'Input',
  },
  {
    label: '日期查询',
    field: 'createTime_begin',
    // field: 'createTime_end',
    component: 'RangeDate',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
];

// 表单数据
export const formSchema: FormSchema[] = [
  {
    label: '任务类型',
    field: 'taskType',
    defaultValue: 1,
    component: 'Input',
    show: false,
  },
  {
    label: '设备任务',
    field: 'business',
    component: 'JDictSelectTag',
    componentProps: {
      type: 'radioButton',
      dictCode: 'task_business',
      placeholder: '请选择类型',
      stringToNumber: true,
    },
    defaultValue: '0',
    rules: [{ required: true, trigger: 'blur' }],
  },
  {
    rules: [{ required: true, trigger: 'blur' }],
    field: 'deviceId',
    component: 'JPopup',
    label: '设备选择',
    helpMessage: ['设备选择'],
    colProps: {
      span: 24,
    },
    componentProps: ({ formActionType }) => {
      let { setFieldsValue } = formActionType;
      return {
        setFieldsValue: setFieldsValue,
        placeholder: '请选择',
        code: 'seal_device_task',
        fieldConfig: [
          { source: 'code', target: 'code' },
          { source: 'id', target: 'deviceId' },
        ],
        multi: false,
      };
    },
  },
  {
    label: '设备编号',
    field: 'code',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'sealLeadId',
    component: 'JPopup',
    label: '铅封选择',
    helpMessage: ['component模式'],
    colProps: {
      span: 24,
    },
    ifShow: ({ values }) => {
      return values.business == '1';
    },
    componentProps: ({ formActionType }) => {
      let { setFieldsValue } = formActionType;
      return {
        setFieldsValue: setFieldsValue,
        param: {
          abc: "'00000001'",
        },
        placeholder: '请选择',
        code: 'seal_lead',
        fieldConfig: [{ source: 'id', target: 'sealLeadId' }],
        multi: true,
      };
    },
    rules: [{ required: true, message: '请选择铅封', trigger: 'blur' }],
  },
  // {
  //   label: '油站名称',
  //   field: 'station',
  //   component: 'Input',
  // },
  {
    label: '备注',
    field: 'note',
    component: 'Input',
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
// 高级查询数据
export const superQuerySchema = {
  taskType: { title: '任务类型', order: 1, view: 'text', type: 'string' },
  deviceId: { title: '设备ID', order: 2, view: 'text', type: 'string' },
  note: { title: '备注', order: 3, view: 'text', type: 'string' },
  status: { title: '任务状态', order: 4, view: 'number', type: 'number' },
  username: { title: '用户名称', order: 5, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
